
<?php require_once("core/functions.php"); ?>
<?php 
    $action = "viewAll";

    if (isset($_GET["activityId"])) {
        $view = new ActivityController($_REQUEST["activityId"]);

        if ($view->activityExists()) {
            $action = "specificView";
        }
    }
?>
<?php $title="Activity" ?>
<?php require_once("header.php"); ?>
<div class="centerContent">
<?php
    if ($action == "viewAll") {
        $data = ActivityController::getAllActivities("0000-00-00");
        for ($i = 0; $i < count($data); $i++) {
        $activity = new ActivityController($data[$i]['activityId']);
?>
            <div class="list" onclick='UTSDK.redirect("viewActivity.php?activityId=<?= $data[$i]['activityId']?>");'>
                <h2>Activity: <?= $activity->getTitle() ?></h2>
                <table class="listTable">
                    <tr><td colspan="2">
                            <h4  class="wordWrap"><i><?= $activity->getDescription() ?></i></h4>
                        </td></tr>
                    <tr><td><b>Date : </b></td><td><?= $activity->getStartAndEndDates() ?></td></tr>
                    <tr><td><b>Event : </b></td>
                        <td><a href="viewEvent.php?eventId=<?= $activity->getEventId() ?>">View <?= $activity->getEventName() ?></a></td></tr>
                    <tr>
                        <td colspan="2">
                            <a href="viewActivity.php?activityId=<?= $data[$i]['activityId']?>"><i>View Activity</i></a>
                        </td>
                    </tr>
                </table>
            </div>
<?php
        }
    }
    else if ($action == "specificView") {
        ?>
        <button onclick="UTSDK.redirect('viewEvent.php?eventId=<?= $view->getEventId() ?>')">Go to Event</button>
        <table border="0">
            <tr><td colspan="2"><h1><?= $view->getTitle(); ?></h1></td></tr>
            <tr><td colspan="2" class="wordWrap"><i><?= $view->getDescription(); ?></i></td></tr>
            <tr><td><b>Start and End Date : </b></td><td><?= $view->getStartAndEndDates() ?></td></tr>
            <tr><td><b>Start and End Time : </b></td><td><?= $view->getStartAndEndTimes() ?></td></tr>
            <tr><td colstpan="2"><h2>Roles : </h2></td><td>
            <tr><td colspan="2">
            <?php
            $data = $view->getRoles();
            if(count($data) == 0){
                echo "There are no roles in activity";
            }
            for ($i = 0; $i < count($data); $i++) {
            $role = new RoleController($data[$i]['roleId']);
                ?>
                <div class="list" onclick='UTSDK.redirect("viewRole.php?roleId=<?= $data[$i]['roleId'] ?>");'>
                    <h2>Role: <?= $role->getTitle() ?></h2>
                    <table class="listTable">
                        <tr>
                            <td colspan="2">
                                <h4 class="wordWrap"><i><?= $role->getDescription() ?></i></h4>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <a href="viewRole.php?roleId=<?= $data[$i]['roleId'] ?>"><i>View Role</i></a>
                            </td>
                        </tr>
                    </table>
                </div>                
            <?php
            }
            ?>

            </td></tr>
        </table>
<?php
    } 
    else if ($action == "dateView") {
        $data = ActivityController::getAllActivities($date);
        for ($i = 0; $i < count($data); $i++) {
        $activity = new ActivityController($data[$i]['activityId']);
?>
            <div class="list" onclick='UTSDK.redirect("viewActivity.php?activityId=<?= $data[$i]['activityId']?>");'>
                <h2>Activity: <?= $activity->getTitle() ?></h2>
                <table class="listTable">
                    <tr><td colspan="2">
                            <h4 class="wordWrap"><i><?= $activity->getDescription() ?></i></h4>
                        </td></tr>
                    <tr><td><b>Date : </b></td><td><?= $activity->getStartAndEndDates() ?></td></tr>
                    <tr><td><b>Event : </b></td>
                        <td><a href="viewEvent.php?eventId=<?= $activity->getEventId() ?>">View <?= $activity->getEventName() ?></a></td></tr>
                    <tr>
                        <td colspan="2">
                            <a href="viewActivity.php?activityId=<?= $data[$i]['activityId']?>"><i>View Activity</i></a>
                        </td>
                    </tr>
                </table>
            </div>
<?php
        }
    }
?>
</div>

<?php require_once("footer.php");
